<?php
class setpwdAction extends security_normal {
	
	function action(){
		$loginname=$this->_getParamId(1);
		$forgetpwd=$this->_getParamId(2);

		$miceSession = new session();

		global $conn;
		if($miceSession->get('mu__userid')){
			$user=new model_User();
			$user->setSubsection('WHERE loginname='.$miceSession->get('mu__loginname'));
			$results=$user->doSelectOne();

			$password1=$_POST['pwd1'];
			$password2=$_POST['pwd2'];
			$pwd='';
			if($password1==$password2 and strlen($password1)>4)
			{
				$salt = md5(rand(100000, 999999).$_POST['loginname']);
				$pwd=sha1($salt.$password1);
			}

			if($results)
			{
				if(strlen($pwd)>0){
					$user->setSalt($salt);
					$user->setPassword($pwd);
				}
				$user->setForgetpwd('');
				$results=$user->doUpdate();

				if($results)
					$exeresult='密码修改成功，请使用新密码登录网站';
				else
					$exeresult='验证错误，请联系网站管理员!';
			}else{
				$exeresult='验证错误，请联系网站管理员!';
			}
			MessageBox('重设密码',MICE_URL,$exeresult);
			exit;
		}elseif(strlen($loginname) AND strlen($forgetpwd)){
			$user=new model_User();
			$user->setSubsection("WHERE loginname='".strtolower($loginname)."' AND forgetpwd='".$forgetpwd."'");
			$results=$user->doSelectOne();

			if(!$results){
				MessageBox('重设密码',MICE_URL,'验证错误，请联系网站管理员!');
				exit;
			}
		}else{
			MessageBox('重设密码',MICE_URL,'验证错误，请联系网站管理员!');
			exit;
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("name",$name);
		$smarty->assign("results",$results);
		$smarty->assign("checkcode",MICE_URL.'code.php');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>